package com.example.game_app.util;

import android.content.Context;
import android.content.SharedPreferences;

public class UserContext {
    /**
     * 登录后，保存当前用户信息
     *
     * @param context
     * @param userId
     */
    public static void setUser(Context context, String userId) {
        SharedPreferences preferences = context.getSharedPreferences("user", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("userId", userId);
        editor.apply();
    }
    public static String getUser(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("user", Context.MODE_PRIVATE);
        return preferences.getString("userId", "");
    }

    /**
     * 新增攻略后，保存当前攻略id
     * @param context
     * @param strategyId
     */
    public static void setStrategy(Context context, String strategyId) {
        SharedPreferences preferences = context.getSharedPreferences("strategy", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("strategyId", strategyId);
        editor.apply();
    }



    public static String getStrategy(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("strategy", Context.MODE_PRIVATE);
        return preferences.getString("strategyId", "");
    }
}
